import React, { useState } from 'react';
import CommonPage from '@/components/page/CommonPage';
const daoName = 'Zxjl';
const importName = 'Zxjl';
const columns: API.Column[] = [
  {
    title: '部门',
    width: 110,
    sorter: true,
    key: 'BMMC',
    dataIndex: 'BMMC',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '员工号',
    width: 110,
    sorter: true,
    dataIndex: 'EMNO',
    key: 'EMNO',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '员工名',
    width: 110,
    sorter: true,
    dataIndex: 'EMNM',
    key: 'EMNM',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '奖励名称',
    width: 110,
    sorter: true,
    key: 'JLMC',
    dataIndex: 'JLMC',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '奖励金额',
    width: 110,
    sorter: true,
    key: 'JLJE',
    dataIndex: 'JLJE',
    dispaly: true,
    filter: true,
    export: true,
  },
];
const controls: API.Control[] = [
  { name: 'BMMC', type: 'text', label: '部门', grid: 12 / 24 },
  { name: 'EMNO', type: 'text', label: '员工号', grid: 12 / 24 },
  { name: 'EMNM', type: 'text', label: '员工名', grid: 12 / 24 },
  { name: 'JLMC', type: 'text', label: '奖励名称', grid: 12 / 24 },
  { name: 'NFJD', dataType: 'date', type: 'date', label: '打分日期', grid: 12 / 24 },
  {
    name: 'JLJE',
    rules: [{ required: true }],
    type: 'number',
    label: '奖励金额',
    grid: 12 / 24,
    dataType: 'number',
  },
];

const controlsImport: API.Control[] = [
  { name: 'BMMC', type: 'text', label: '部门', grid: 12 / 24 },
  { name: 'EMNO', type: 'text', label: '员工号', grid: 12 / 24 },
  { name: 'EMNM', type: 'text', label: '员工名', grid: 12 / 24 },
  { name: 'JLMC', type: 'text', label: '奖励名称', grid: 12 / 24 },
  {
    name: 'JLJE',
    rules: [{ required: true }],
    type: 'number',
    label: '奖励金额',
    grid: 12 / 24,
    dataType: 'number',
  },
];
const Zxjl: React.FC = () => {
  const currentDate = new Date();
  const currentYear = currentDate.getFullYear();
  const currentMonth = currentDate.getMonth() + 1;
  let lastMonthFirstDay: string;
  if (currentMonth == 1) {
    lastMonthFirstDay = currentYear + '-01-01';
  } else if (currentMonth == 2) {
    lastMonthFirstDay = currentYear + '-02-01';
  } else if (currentMonth == 3) {
    lastMonthFirstDay = currentYear + '-03-01';
  } else if (currentMonth == 4) {
    lastMonthFirstDay = currentYear + '-04-01';
  } else if (currentMonth == 5) {
    lastMonthFirstDay = currentYear + '-05-01';
  } else if (currentMonth == 6) {
    lastMonthFirstDay = currentYear + '-06-01';
  } else if (currentMonth == 7) {
    lastMonthFirstDay = currentYear + '-07-01';
  } else if (currentMonth == 8) {
    lastMonthFirstDay = currentYear + '-08-01';
  } else if (currentMonth == 9) {
    lastMonthFirstDay = currentYear + '-09-01';
  } else if (currentMonth == 10) {
    lastMonthFirstDay = currentYear + '-10-01';
  } else if (currentMonth == 11) {
    lastMonthFirstDay = currentYear + '-11-01';
  } else {
    lastMonthFirstDay = currentYear + '-12-01';
  }
  const [selDate, setSelDate] = useState<string>(lastMonthFirstDay);
  const [zbid, setZbid] = useState<number>(1);
  const setParas2 = (row: Record<string, any>) => {
    setSelDate(row.NFJD);
    setZbid(row.ZBID);
  };
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      title="专项奖励"
      importName={importName}
      importControls={controlsImport}
      importMode="DeleteAfterInsert"
      importParamNames={['NFJD', 'ZBID']}
      importTemplateName="专项奖励导入模板"
      importParamVals={{
        NFJD: selDate,
        ZBID: '' + zbid,
      }}
      keyColName="ID"
      onShortcutChange={async (vals) => setParas2(vals)}
      shortcutFilters={{
        controls: [
          {
            name: 'NFJD',
            dataType: 'date',
            type: 'month',
            label: '选择月份',
            initValue: selDate,
            rules: [{ required: true, message: '月份不能为空' }],
            width: 120,
          },
          {
            name: 'ZBID',
            label: '选择条线',
            type: 'select',
            width: 180,
            grid: 12 / 24,
            rules: [{ required: true, message: '条线不能为空' }],
            dataType: 'number',
            initValue: zbid,
            fetch: {
              tableName: 'Zxjezb',
              optionTpl: 'ZBMC',
              valueTpl: 'ZBID',
              isDao: true,
            },
          },
        ],
      }}
    />
  );
};
export default Zxjl;
